home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 105 (1991-02)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 105 (1991-02)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / AmigaUUCP / uucico / time.c < prev    next >
C/C++ Source or Header  |  1990-05-18  |  2KB  |  111 lines

  1.  
  2. /*
  3.  *  TIME.C
  4.  *
  5.  *  By Christopher A. Wichura
  6.  *
  7.  *  Note: cannot use strtok() due to parent level's use of it.
  8.  */
  9.  
  10. #include "includes.h"           /* System include files, system dependent */
  11. #include "uucp.h"               /* Uucp definitions and parameters */
  12. #include <log.h>
  13. #include "version.h"
  14.  
  15. typedef struct tm   Time;
  16.  
  17. char Days[7][3] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
  18.  
  19. int
  20. CheckTimeRestrictions(timeStr)
  21. char *timeStr;
  22. {
  23.     Time *tm;
  24.     char *ptr;
  25.     int work1;
  26.     int work2;
  27.     int starth, startm;
  28.     int endh,    endm;
  29.     char Hours[24];
  30.     int result;
  31.     int day;
  32.  
  33.     if (strnicmp("Any", timeStr, 3) == 0)
  34.     return (SUCCESS);
  35.  
  36.     if (strnicmp("Never", timeStr, 5) == 0)
  37.     return (FAIL);
  38.  
  39.     {
  40.     time_t t;
  41.     time (&t);
  42.     tm = localtime(&t);
  43.     }
  44.  
  45.     result = FAIL;
  46.  
  47.     for (ptr = timeStr; ptr; ptr = strpbrk(ptr, ",")) {
  48.     if (*ptr == ',')
  49.         ++ptr;
  50.  
  51.     day = 0;
  52.  
  53.     while (isalpha(*ptr)) {
  54.         for (work1 = 0; work1 < 7; ++work1) {
  55.         if (strnicmp(ptr, Days[work1], 2) == 0) {
  56.             day |= 1L << work1;
  57.             ptr += 2;
  58.             break;
  59.         }
  60.         }
  61.         if (work1 == 7) {
  62.         ulog(-1, "Illegal DOW Field (L.Sys): %s", timeStr);
  63.         return(FAIL);
  64.         }
  65.     }
  66.  
  67.     if (day == 0)
  68.         day = -1;
  69.  
  70.     if (sscanf(ptr, "%d:%d-%d:%d", &starth, &startm, &endh, &endm) != 4) {
  71.         ulog(-1, "Illegal Time Range Field (L.Sys): %s", timeStr);
  72.         return(FAIL);
  73.     }
  74.  
  75.     /*
  76.      * at this point we have start and end times.  check them against
  77.      * current system time
  78.      */
  79.  
  80.     setmem(Hours, sizeof(Hours), 0);
  81.  
  82.     work1 = endh - starth;
  83.     if (work1 < 0)
  84.         work1 += 24;
  85.  
  86.     work1 = starth + work1;
  87.     work2 = starth;
  88.  
  89.     while (work2 <= work1) {
  90.         Hours[work2++] = 1;
  91.  
  92.         if (work2 == 24)
  93.         work1 -= 24, work2 -=24;
  94.     }
  95.  
  96.     for (;;) {
  97.         if (!(day & 1L << tm->tm_wday))
  98.         break;
  99.         if (!Hours[tm->tm_hour])
  100.         break;
  101.         if (tm->tm_hour == starth && tm->tm_min < startm)
  102.         break;
  103.         if (tm->tm_hour == endh && tm->tm_min > endm)
  104.         break;
  105.         return(SUCCESS);
  106.     }
  107.     }
  108.     return (FAIL);
  109. }
  110.  
  111.